<?php

namespace App\Http\Controllers\YApi;

//use Illuminate\Http\Request;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Session;
use Redirect;

use App\Models\Book;
use App\Models\BooksPingfen;

class BookslistController extends Controller
{

    public function bookslist()
    {
        //书籍列表
        $pre_page = 15;
        //$posts = Book::paginate($pre_page);
        $books = Book::orderBy('last_update', 'desc')->orderBy('book_id', 'desc')
            ->select(['book_id','bimg','book_name','zuozhe','chubannian','chubanshe'])
            ->paginate($pre_page);
        
        $uid = request::input('uid');

        foreach($books as $book)
        {
            $book['read_state'] = BooksPingfen::where('book_id', $book->book_id)->where('uid', $uid)->first();
        }
        
        return $books;
    }
    
}